angular.module('Controller')
.controller('WfMapModalCtrl',($scope,activeParam,$localStorage,NgTableParams,commonUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.result={name:undefined}
    $scope.result.name=items.data.name if items.data
    $scope.type=type=items.type
    placeSearch=undefined
    loadMap=()->
#        console.log(document.getElementById("tipinput"));
        map = new AMap.Map("map-container", {
            resizeEnable: true
        });
#        console.log('map',map);
        autoOptions = {
            input: "tipinput"
        };
        auto = new AMap.Autocomplete(autoOptions);
#        console.log('auto',auto)
        placeSearch = new AMap.PlaceSearch({
            map: map
        });
        AMap.event.addListener(auto, "select", select);
        AMap.event.addListener(placeSearch,'markerClick',markerClick);
        placeSearch.search($scope.result.name) if $scope.result.name
    _.defer(->
        loadMap()
    )
    select=(e)->
#        console.log(JSON.stringify(e));
        placeSearch.setCity(e.poi.adcode);
        placeSearch.search(e.poi.name)
#    pickRes=(status,result)->
#        console.log(JSON.stringify(result));
    markerClick=(obj)->
#        console.log(obj.data);
        if type!='view'
            $scope.result=obj.data;
            $scope.$digest()
    $scope.confirm = ()->
        $uibModalInstance.close($scope.result)
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')

)